<div class="page-header clearfix">
  <ol ng-if="action === 'create'" class="heading">
    <li><a ui-sref="main.categories">内容分类</a></li>
    <li><a ui-sref="main.categories.create">新增分类</a></li>
  </ol>
  <ol ng-if="action === 'update'" class="heading">
    <li><a ui-sref="main.categories">内容分类</a></li>
    <li><a ui-sref="main.categories.update({ _id: _id })">更新分类</a></li>
  </ol>
</div>
<div class="panel panel-default">
  <div class="panel-body">
    <form ng-submit="saveCategory()" class="form-horizontal" id="categoryForm" name="categoryForm" novalidate>
      <div ng-class="{ 'has-error': categoryForm.types.$touched && categoryForm.types.$invalid}" class="form-group">
        <label for="types" class="col-sm-2 control-label">* 分类类型：</label>
        <div class="col-sm-10">
          <div ng-if="action === 'create'" class="btn-group" role="group" aria-label="...">
            <button ng-repeat="type in $parent.types" ng-click="$parent.$parent.type = type.type" ng-disabled="transmitting" ng-class="{ 'active': $parent.$parent.type === type.type }" class="btn btn-default" id="types" type="button">{{type.name}}</button>
          </div>
          <p ng-if="action === 'update'" class="form-control-static">{{translateType(type)}}</p>
        </div>
      </div>
      <div ng-class="{ 'has-error': categoryForm.name.$touched && categoryForm.name.$invalid }" class="form-group">
        <label for="name" class="col-sm-2 control-label">* {{type | translate: { display: 'name', same: 'type', source: types } }}名：</label>
        <div class="col-sm-10">
          <input ng-model="name" ng-disabled="transmitting" class="form-control" id="name" type="text" name="name" placeholder="请输入{{type | translate: { display: 'name', same: 'type', source: types } }}名" required>
        </div>
      </div>
      <div ng-class="{ 'has-error': categoryForm.sort.$touched && categoryForm.sort.$invalid }" class="form-group">
        <label for="sort" class="col-sm-2 control-label">排序：</label>
        <div class="col-sm-10">
          <input ng-model="sort" ng-disabled="transmitting" class="form-control" id="sort" type="number" name="sort" min="0" required>
        </div>
      </div>
      <div ng-class="{ 'has-error': categoryForm.isShow.$touched && categoryForm.isShow.$invalid }" class="form-group">
        <label for="isShow" class="col-sm-2 control-label">显示：</label>
        <div class="col-sm-10">
          <div class="checkbox">
            <label>
              <input ng-model="isShow" ng-disabled="transmitting" id="isShow" type="checkbox">
              在导航栏中显示
            </label>
          </div>
        </div>
      </div>
      <hr>
      <div ng-if="type === 'page' || type === 'link'" ng-class="{ 'has-error': categoryForm.parentCategory.$touched && categoryForm.parentCategory.$invalid}" class="form-group">
        <label for="parentCategory" class="col-sm-2 control-label">上级分类：</label>
        <div class="col-sm-10">
          <select ng-if="action === 'create'" ng-model="$parent.$parent.prePath" ng-options="category.path as category.name for category in $parent.$parent.$parent.categories | filter: { type: '!column' } | filter: { type: '!link'}" ng-disabled="transmitting" class="form-control" id="parentCategory" name="parentCategory">
            <option value="">作为顶级分类</option>
          </select>
          <select ng-if="action === 'update'" ng-model="$parent.$parent.prePath" ng-options="category.path as category.name for category in $parent.$parent.$parent.categories | filter: { type: '!column' } | filter: { type: '!link'} | filter: { _id: '!{{ _id }}' } | filter: { path: '!{{ oldPath }}' }" ng-disabled="transmitting" class="form-control" id="parentCategory" name="parentCategory">
            <option value="">作为顶级分类</option>
          </select>
        </div>
      </div>
      <div ng-if="type === 'column'" ng-class="{ 'has-error': categoryForm.model.$touched && categoryForm.model.$invalid}" class="form-group">
        <label for="model" class="col-sm-2 control-label">* 内容模型：</label>
        <div class="col-sm-10">
          <select ng-model="$parent.model" ng-options="models._id as models.name for models in $parent.models" ng-disabled="$parent.transmitting" class="form-control" id="model" name="model" required>
            <option value="">请选择模型</option>
          </select>
        </div>
      </div>
      <div ng-if="type === 'column'" ng-class="{ 'has-error': categoryForm.parentCategory.$touched && categoryForm.parentCategory.$invalid}" class="form-group">
        <label for="parentCategory" class="col-sm-2 control-label">上级分类：</label>
        <div class="col-sm-10">
          <select ng-model="$parent.prePath" ng-options="category.path as category.name for category in $parent.$parent.categories | filter: { type: 'channel' }" ng-disabled="transmitting" class="form-control" id="parentCategory" name="parentCategory">
            <option value="">作为顶级分类</option>
          </select>
        </div>
      </div>
      <!-- 存在 categoryForm.directory.$touched-->
      <div ng-if="type !== 'link' && action === 'create'" ng-class="{ 'has-error': categoryForm.directory.$touched && categoryForm.directory.$invalid }" class="form-group has-feedback">
        <label for="directory" class="col-sm-2 control-label">* 目录：</label>
        <div class="col-sm-10">
          <input ng-model="$parent.directory" ng-pattern="/^[A-z0-9\-\_]+$/" nd-vdirectory pre-path="prePath" old-path="oldPath" ng-trim ng-disabled="transmitting" class="form-control text-lowercase" id="directory" type="text" name="directory" describedby="directoryStatus" placeholder="请输入目录" required>
          <span ng-show="checkDirectorying" class="form-control-feedback" aria-hidden="true"><i class="fa fa-refresh fa-spin"></i></span>
          <span id="directoryStatus" class="sr-only">(检测中)</span>
          <p ng-show="categoryForm.directory.$error.pattern && categoryForm.directory.$touched && categoryForm.directory.$invalid" class="help-block">仅能使用大小写字母、数字、中划线以及下划线</p>
          <p ng-show="!categoryForm.directory.$error.pattern && categoryForm.directory.$error.vdirectory && categoryForm.directory.$touched && categoryForm.directory.$invalid" class="help-block">该目录名已经存在或为保留名</p>
        </div>
      </div>
      <!-- 因为是更新所以不存在 categoryForm.directory.$touched-->
      <div ng-if="type !== 'link' && action === 'update'" ng-class="{ 'has-error': categoryForm.directory.$invalid }" class="form-group has-feedback">
        <label for="directory" class="col-sm-2 control-label">* 目录：</label>
        <div class="col-sm-10">
          <input ng-model="$parent.directory" ng-pattern="/^[A-z0-9\-\_]+$/" nd-vdirectory pre-path="prePath" old-path="oldPath" ng-trim ng-disabled="transmitting" class="form-control text-lowercase" id="directory" type="text" name="directory" describedby="directoryStatus" placeholder="请输入目录" required>
          <span ng-show="checkDirectorying" class="form-control-feedback" aria-hidden="true"><i class="fa fa-refresh fa-spin"></i></span>
          <span id="directoryStatus" class="sr-only">(检测中)</span>
          <p ng-show="categoryForm.directory.$error.pattern && categoryForm.directory.$invalid" class="help-block">仅能使用大小写字母、数字、中划线以及下划线</p>
          <p ng-show="!categoryForm.directory.$error.pattern && categoryForm.directory.$error.vdirectory && categoryForm.directory.$invalid" class="help-block">该目录名已经存在或为保留名</p>
        </div>
      </div>
      <div ng-if="type === 'column'" ng-class="{ 'has-error': categoryForm.pageSize.$touched && categoryForm.pageSize.$invalid }" class="form-group">
        <label for="pageSize" class="col-sm-2 control-label">* 每页条数：</label>
        <div class="col-sm-10">
          <input ng-model="$parent.pageSize" ng-disabled="transmitting" class="form-control" id="pageSize" type="number" min="1" name="pageSize" placeholder="请输入每页条数" required>
        </div>
      </div>
      <div ng-if="type === 'link'" ng-class="{ 'has-error': categoryForm.url.$touched && categoryForm.url.$invalid }" class="form-group">
        <label for="url" class="col-sm-2 control-label">* 网址：</label>
        <div class="col-sm-10">
          <input ng-model="$parent.url" ng-disabled="transmitting" class="form-control" id="url" type="url" name="url" placeholder="请输入 URL" required>
        </div>
      </div>
      <div ng-if="type !== 'link'" ng-class="{ 'has-error': categoryForm.layoutView.$touched && categoryForm.layoutView.$invalid}" class="form-group">
        <label for="layoutView" class="col-sm-2 control-label">* 布局模板：</label>
        <div class="col-sm-10">
          <select ng-model="$parent.views.layout" ng-options="view as view for view in $parent.viewfiles | filter: 'layout-'" ng-disabled="$parent.transmitting" class="form-control" id="layoutView" name="layoutView" required></select>
        </div>
      </div>
      <div ng-if="type === 'channel'" ng-class="{ 'has-error': categoryForm.channelView.$touched && categoryForm.channelView.$invalid}" class="form-group">
        <label for="columnView" class="col-sm-2 control-label">* 频道页模板：</label>
        <div class="col-sm-10">
          <select ng-model="$parent.views.channel" ng-options="view for view in $parent.viewfiles | filter: 'channel-'" ng-disabled="$parent.transmitting" class="form-control" id="channelView" name="channelView" required></select>
        </div>
      </div>
      <div ng-if="type === 'column'" ng-class="{ 'has-error': categoryForm.columnView.$touched && categoryForm.columnView.$invalid}" class="form-group">
        <label for="columnView" class="col-sm-2 control-label">* 栏目页模板：</label>
        <div class="col-sm-10">
          <select ng-model="$parent.views.column" ng-options="view for view in $parent.viewfiles | filter: 'column-'" ng-disabled="$parent.transmitting" class="form-control" id="columnView" name="columnView" required></select>
        </div>
      </div>
      <div ng-if="type === 'column'" ng-class="{ 'has-error': categoryForm.contentView.$touched && categoryForm.contentView.$invalid}" class="form-group">
        <label for="contentView" class="col-sm-2 control-label">* 内容页模板：</label>
        <div class="col-sm-10">
          <select ng-model="$parent.views.content" ng-options="view for view in $parent.viewfiles | filter: 'content-'" ng-disabled="$parent.transmitting" class="form-control" id="contentView" name="contentView" required></select>
        </div>
      </div>
      <div ng-if="type === 'page'" ng-class="{ 'has-error': categoryForm.pageView.$touched && categoryForm.pageView.$invalid}" class="form-group">
        <label for="pageView" class="col-sm-2 control-label">* 单页模板：</label>
        <div class="col-sm-10">
          <select ng-model="$parent.views.page" ng-options="view for view in $parent.viewfiles | filter: 'page-'" ng-disabled="$parent.transmitting" class="form-control" id="pageView" name="pageView" required></select>
        </div>
      </div>
      <div ng-if="type === 'page'" ng-class="{ 'has-error': categoryForm.isEdit.$touched && categoryForm.isEdit.$invalid }" class="form-group">
        <label for="isEdit" class="col-sm-2 control-label">可编辑：</label>
        <div class="col-sm-10">
          <div class="checkbox">
            <label>
              <input ng-model="$parent.isEdit" ng-disabled="transmitting" id="isEdit" type="checkbox">
              允许在后台编辑
            </label>
          </div>
        </div>
      </div>
      <div ng-if="type !== 'link'" class="form-group">
        <label for="keywords" class="col-sm-2 control-label">关键词：</label>
        <div class="col-sm-10">
          <input ng-model="$parent.keywords" ng-disabled="$parent.transmitting" class="form-control" id="keywords" type="text" name="keywords" placeholder="META Keywords（网站关键词）">
        </div>
      </div>
      <div ng-if="type !== 'link'" class="form-group">
        <label for="description" class="col-sm-2 control-label">描述：</label>
        <div class="col-sm-10">
          <textarea ng-model="$parent.description" ng-disabled="$parent.transmitting" class="form-control" id="description" name="description" rows="3" placeholder="META Description（网站描述）"></textarea>
        </div>
      </div>
      
    </form>
  </div>
</div>
<button ng-disabled="transmitting || inputing || categoryForm.$invalid" class="btn btn-primary pull-right" form="categoryForm" type="submit"><i class="fa fa-save"></i> 保存分类</button>